#
#	genx_parameters.py
#
#	David Janes
#	2008.08.16
#
#	GenX - search, create and insert structured data
#

import sys
import types
import re
import pprint
import cgi
import md5

class Parameters:
	def __init__(self, qs):
		self.qs = qs
		self.qd = cgi.parse_qs(qs)

	def Get(self, key, otherwise = None):
		vs = self.qd.get(key)
		if not vs:
			return	otherwise

		return	vs[0]
		
	def GetAsString(self, key, otherwise = ""):
		return	self.Get(key, otherwise).decode('utf-8')

	def GetAsEnum(self, key, values, otherwise = None):
		if otherwise == None:
			otherwise = values[0]

		value = self.GetAsString(key, otherwise)
		if value not in values:
			return	otherwise

		return	value
